const fs = require('fs')
const path = require('path')
const morgan = require('koa-morgan')//错误日记
const {environment}  =require('../config/config')
const { HttpException } = require('../core/http-exception')
class catchError {
    static catchErrorCore(app) {

        //入口方法
        this.app = app
        this.catchErrorMorgan()
        //   // 线上环境
    }
    static catchErrorMorgan() {
    
        const isDev =environment === 'dev'
        if (!isDev) {
        const logFileName = path.join(process.cwd(), 'logs', 'access.log')
        const writeStream = fs.createWriteStream(logFileName, {
            flags: 'a'
        })
        this.app.use(morgan('combined', {
            stream: writeStream
        }));
    }
}
}
module.exports = catchError